GtkIconCache: Add api to find if directories are empty
authorMatthias Clasen <mclasen@redhat.com>
Fri, 20 Jun 2014 16:11:22 +0000 (12:11 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 20 Jun 2014 16:15:25 +0000 (12:15 -0400)
This will help in not creating structs for tons of empty
directories.

gtk/gtkiconcache.c
gtk/gtkiconcache.h

index 4eaff97b658521752064a0647aa6829987327efe..d19c0a9188744b6e36dc65bc201bb68f0f62c422 100644 (file)
@@ -300,6 +300,48 @@ _gtk_icon_cache_get_icon_flags (GtkIconCache *cache,
   return GET_UINT16 (cache->buffer, image_offset + 2);
 }
 
+gboolean
+_gtk_icon_cache_has_icons (GtkIconCache *cache,
+                          const gchar  *directory)
+{
+  int directory_index;
+  guint32 hash_offset, n_buckets;
+  guint32 chain_offset;
+  guint32 image_list_offset, n_images;
+  int i, j;
+
+  directory_index = get_directory_index (cache, directory);
+
+  if (directory_index == -1)
+    return FALSE;
+
+  hash_offset = GET_UINT32 (cache->buffer, 4);
+  n_buckets = GET_UINT32 (cache->buffer, hash_offset);
+
+  for (i = 0; i < n_buckets; i++)
+    {
+      chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i);
+      while (chain_offset != 0xffffffff)
+       {
+         guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
+
+         image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
+         n_images = GET_UINT32 (cache->buffer, image_list_offset);
+
+         for (j = 0; j < n_images; j++)
+           {
+             if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) ==
+                 directory_index)
+               return TRUE;
+           }
+
+         chain_offset = GET_UINT32 (cache->buffer, chain_offset);
+       }
+    }
+
+  return FALSE;
+}
+
 void
 _gtk_icon_cache_add_icons (GtkIconCache *cache,
                           const gchar  *directory,
index 767e2b62cc632d22f92e6e9efc01ade1cc7181e8..1ec47b00e27e082ecabf02a79d96a23ede11a6c8 100644 (file)
@@ -44,6 +44,8 @@ gboolean      _gtk_icon_cache_has_icon       (GtkIconCache *cache,
 gboolean      _gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache,
                                                     const gchar  *icon_name,
                                                     const gchar  *directory);
+gboolean      _gtk_icon_cache_has_icons      (GtkIconCache *cache,
+                                              const gchar  *directory);
 void         _gtk_icon_cache_add_icons      (GtkIconCache *cache,
                                              const gchar  *directory,
                                              GHashTable   *hash_table);